<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/18
 * Time: 10:41
 */

namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use app\admin\model\StockModel;
use mindplay\annotations\IAnnotationFileAware;
use think\Request;
use think\Session;

class StockController extends AdminBaseController
{
    public function stockList()
    {
        $stockModel = new StockModel();
        $data = $stockModel->stockList();
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function getGoodsInfo()
    {
        $param = $this->request->param();
        $stockModel = new StockModel();
        $goodsInfo = $stockModel->goodsContent($param['goods_id']);
        return json($goodsInfo);
    }

    //添加库存
    public function addStock()
    {
        return $this->fetch();
    }

    //提交添加
    public function addStockSuccess()
    {
        $param = $this->request->param();
        $goodsArr = $param['goodsArr'];
        $stockModel = new StockModel();
        $res = $data = $stockModel->writekuchun($goodsArr);
        if ($res) {
            return 200;
        } else {
            return 201;
        }
    }

    //删除
    public function delStock()
    {
        $param = $this->request->param();
        $id = $param['id'];
        $arr = Session::get("addArr");
        unset($arr[$id]);
        Session::set("addArr", $arr);
        return $this->redirect("addStock");
    }

}